# Function for Aggregating Behavioral Proclivities 

get_dummy_lab <- function(new_var, old_vars, pos_level, neg_level) {
  for(i in 1:length(old_vars)) {
    # uses <<- to perform assignment in global environment:
    lab[,new_var][lab[,old_vars[i]] == pos_level] <<- 1
    lab[,new_var][lab[,old_vars[i]] == neg_level] <<- 0
  }
  return(data)
}


# Conative Attitudes ------------------------------------------------------

# Absenteeism -------------------------------------------------------------

abs_vars <- c("lc1",
              "pta",
              "bring_up",
              "assemble")

lab[,abs_vars] <- NA

labcb$fire_teach_q10_1_1$answer[2,]
labcb$fire_teach_q10_1_2$answer[2,]
labcb$fire_teach_q10_1_3$answer[2,]
labcb$fire_teach_q10_1_4$answer[2,]
labcb$pta_q10_2_1$answer[1,]
labcb$pta_q10_2_2$answer[1,]
labcb$pta_q10_2_3$answer[1,]
labcb$pta_q10_2_4$answer[1,]
labcb$bring_up_q10_3_1$answer[2,]
labcb$bring_up_q10_3_2$answer[2,]
labcb$bring_up_q10_3_3$answer[2,]
labcb$bring_up_q10_3_4$answer[2,]
labcb$assemble_q10_4_1$answer[1,]
labcb$assemble_q10_4_2$answer[1,]
labcb$assemble_q10_4_3$answer[1,]
labcb$assemble_q10_4_4$answer[1,]

mapply(FUN = get_dummy_lab,
       new_var = abs_vars,
       old_vars = list(c("fire_teach_q10_1_1",
                         "fire_teach_q10_1_2",
                         "fire_teach_q10_1_3",
                         "fire_teach_q10_1_4"),
                       c("pta_q10_2_1",
                         "pta_q10_2_2",
                         "pta_q10_2_3",
                         "pta_q10_2_4"),
                       c("bring_up_q10_3_1",
                         "bring_up_q10_3_2",
                         "bring_up_q10_3_3",
                         "bring_up_q10_3_4"),
                       c("assemble_q10_4_1",
                         "assemble_q10_4_2",
                         "assemble_q10_4_3",
                         "assemble_q10_4_4")),
       pos_level = c(2,1,2,1),
       neg_level = c(1,2,1,2))

rm(abs_vars)

# Additional variables for repsondents who are LC1s

lc1s <- c("fire_teach_q10_1_1_2",
          "fire_teach_q10_1_2_2",
          "fire_teach_q10_1_3_2",
          "fire_teach_q10_1_4_2")

labcb$fire_teach_q10_1_1_2$answer[2,]
labcb$fire_teach_q10_1_2_2$answer[2,]
labcb$fire_teach_q10_1_3_2$answer[2,]
labcb$fire_teach_q10_1_4_2$answer[2,]

for(variable in lc1s) {
  lab$lc1[lab[,variable] == 2] <- 1
  lab$lc1[lab[,variable] == 1] <- 0
}

rm(lc1s)



